package com.littleken.foodieService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.littleken.foodieCommon.constant.Constant;
import com.littleken.foodieMapper.CategoryMapper;
import com.littleken.foodiePojo.domain.CategoryDO;
import com.littleken.foodiePojo.vo.CategoryVO;
import com.littleken.foodiePojo.vo.NewItemsVO;
import com.littleken.foodieService.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * Create by littleken on 2020/11/24 10:51
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;

    /**
     * 查询所有根级分类目录
     * @return
     */
    @Override
    public List<CategoryDO> getAllRootLevelCat() {
        List<CategoryDO> categoryList = Lists.newArrayList();
        QueryWrapper<CategoryDO> wrapper = new QueryWrapper<>();

        wrapper.eq("type", Constant.TYPE_ROOT_LEVEL);
        categoryList = categoryMapper.selectList(wrapper);
        return categoryList;
    }

    /**
     * 根据一级分类id查询其下所有三级分类list
     * @param rootCatId
     * @return
     */
    @Override
    public List<CategoryVO> getAllSubCatList(Integer rootCatId) {
        List<CategoryVO> subCatList = Lists.newArrayList();
        subCatList = categoryMapper.getSubCatList(rootCatId);
        return subCatList;
    }

    @Override
    public List<NewItemsVO> getSixNewItemsLazy(Integer rootCatId) {
        List<NewItemsVO> sixNewItemsLazy = Lists.newArrayList();
        Map<String,Object> map = new HashMap<>();
        map.put("rootCatId",rootCatId);
        sixNewItemsLazy = categoryMapper.getSixNewItemsLazy(map);
        return sixNewItemsLazy;
    }

}
